package com.tom.architect02.p4.day38.simple6;

import android.widget.TextView;

import com.tom.architect02.R;
import com.tom.architect02.p4.day38.simple6.base.BaseMvpActivity;
import com.tom.architect02.p4.day38.simple6.inject.InjectPresenter;
import com.tom.architect02.p4.day38.simple6.mvp.UserInfo;
import com.tom.architect02.p4.day38.simple6.mvp.UserInfoContact;
import com.tom.architect02.p4.day38.simple6.mvp.UserInfoPresenter;

// 传递泛型。<UserInfoPresenter>
public class MainActivity3806 extends BaseMvpActivity<UserInfoPresenter> implements UserInfoContact.UserInfoView {
    private TextView mTextView;

    // 多Presenter 如何处理？ Dagger也可以处理。
    // 方式一：也可以多new Presenter, 自己手动去attach关联，detach取消关联。
//    UserInfoPresenter mPresenter1, mPresenter2, ...;
    // 方式二：注解的方式实现一对多。一个View里面有多个Presenter
    @InjectPresenter
    private UserInfoPresenter mPresenter1; // 注入。不要自己new对象。
    @InjectPresenter
    private UserInfoPresenter mPresenter2;

    @Override
    public void onLoading() {
        // 加载进度条
    }
    @Override
    public void onError() {
        // 显示错误
    }

    @Override
    public void onSucceed(UserInfo userInfo) { // 成功了。
        mTextView.setText(userInfo.toString());
    }


    @Override
    protected UserInfoPresenter createPresenter() {
        return new UserInfoPresenter();
    }

    @Override
    protected void initView() {
        mTextView = findViewById(R.id.textView37);
    }

    @Override
    protected void initData() {
        mPresenter1.getUser("token");
//        mPresenter1 = new UserInfoPresenter();
//        mPresenter2 = new UserInfoPresenter();
//        mPresenter1.attach(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        mPresenter1.detach();
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main37);
    }
}
